package net.csdn.business.webhook.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.csdn.business.common.domain.query.WebhookLogQuery;
import net.csdn.business.common.domain.vo.WebhookLogVO;
import net.csdn.business.webhook.entity.WebhookLog;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @ClassName WebhookLogMapper
 * @Description webhook通知日志Mapper接口
 * @Author zhangyl
 * @Date 2023/4/23 17:15
 */
public interface WebhookLogMapper extends BaseMapper<WebhookLog>
{

    /**
     * 分页查询webhook通知日志列表
     *
     * @param query 字典类型信息
     * @return 字典类型集合信息
     */
    @Select("select t1.object_id,t1.delivery_id,t1.trigger_event,t1.res_status,t1.internal_error_message,t1.is_redelivery,t1.created_date FROM webhook_log t1 where t1.web_hook_id=#{query.webHookId} order by t1.created_date desc")
    public List<WebhookLogVO> findPageList(Page page, @Param("query") WebhookLogQuery query);

    /**
     * 查询webhook通知日志
     * 
     * @param id webhook通知日志主键
     * @return webhook通知日志
     */
    @Select("select t1.* FROM webhook_log t1 where t1.object_id=#{id}")
    public WebhookLogVO selectWebhookLogById(@Param("id")String id);

    /**
     * 查询webhook通知日志列表
     * 
     * @param query webhook通知日志
     * @return webhook通知日志集合
     */
    @Select("select t1.* FROM webhook_log t1 where t1.web_hook_id=#{query.webHookId} order by t1.created_date desc")
    public List<WebhookLogVO> selectWebhookLogList(@Param("query") WebhookLogQuery query);

    /**
     * 删除webhook通知日志
     * 
     * @param webHookId webhook配置的主键id
     * @return 结果
     */
    @Delete("DELETE FROM webhook_log where web_hook_id=#{webHookId}")
    public Integer deleteWebhookLogByWebHookId(@Param("webHookId") String webHookId);

    @Select("select t1.res_status,t1.internal_error_message FROM webhook_log t1 where t1.web_hook_id=#{webHookId} order by t1.created_date desc limit 1")
    public WebhookLogVO selectLastWebhookLog(@Param("webHookId")String webhookId);

}
